/*
 * JoinVertex.java
 * 
 * Created on Sep 26, 2007, 1:18:02 PM
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dnbW.queryW.visualW;

import java.util.Map;
import java.util.TreeMap;

/**
 *
 * @author zhouyong
 */

public class JoinVertex extends OperatorVertex{

    private JoinLeafVertex leftLeaf;
    private JoinLeafVertex rightLeaf;
    
    public static String[] OPS = {"=", "!=", ">", "<", ">=", "<="};
    
    public JoinVertex(String op){
        super(op);
    }
    
    public JoinVertex(String op, JoinLeafVertex left, JoinLeafVertex right){
        super(op);
        this.leftLeaf = left;
        this.rightLeaf = right;
    }

    public JoinLeafVertex getLeftLeaf() {
        return leftLeaf;
    }

    public JoinLeafVertex getRightLeaf() {
        return rightLeaf;
    }

    public String getPredicateExpression() {
        int lcp = super.lcp(leftLeaf, rightLeaf);
        
        StringBuilder path1 = new StringBuilder();
        for(int i=lcp + 1; i < leftLeaf.getFullPath().size(); i++){
            path1.append("/");
            path1.append(leftLeaf.getFullPath().get(i).toString());
        }
        
        StringBuilder path2 = new StringBuilder();
        for(int i=lcp + 1; i < rightLeaf.getFullPath().size(); i++){
            path2.append("/");
            path2.append(rightLeaf.getFullPath().get(i).toString());
        }
        
        path1.deleteCharAt(0);
        path2.deleteCharAt(0);
        
        return "(" + path1.toString() + " " + this.getOperator() + " " + path2.toString() + ")";
    }

    @Override
    public Map<Integer, Long> getIdentityPathMapFinal() {
        return new TreeMap<Integer, Long>(this.getIdentityPathMap());
    }
    
    
}
